package kku.cs.fgl.actor;

import java.io.IOException;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.particles.ParticleIO;
import org.newdawn.slick.particles.ParticleSystem;
import org.newdawn.slick.particles.effects.FireEmitter;

import kku.cs.fgl.Actor;

public class ParticleActor extends Actor {
	
	private ParticleSystem particleSystem; 

	public ParticleActor() {
	}

	public ParticleActor(float x, float y) {
		super(x, y);
		particleSystem = new ParticleSystem("particle.png");
		particleSystem.addEmitter(new FireEmitter());
	}	
	public ParticleActor(float x, float y,String file) {
		super(x, y);
		load(file);
	}	
	public void load(String file){
		try {
			particleSystem = ParticleIO.loadConfiguredSystem(file);
			
		} catch (IOException e) {
			e.printStackTrace();
		}		
	}

	public ParticleSystem getParticleSystem() {
		return particleSystem;
	}

	public void setParticleSystem(ParticleSystem particleSystem) {
		this.particleSystem = particleSystem;
	}

	public void paint(Graphics g) {
		if(particleSystem!=null){
		  particleSystem.render(getWidth()/2,getHeight()/2);
		}
	}

	public void update(int time) {
		super.update(time);
		if(particleSystem!=null){
			particleSystem.update(time);
			if(particleSystem.getParticleCount()<=0)
				systemEnd();
		}
	}	
	public void systemEnd(){
		dead();
	}
}
